package com.tte.common;

/**
 * @PackageName: com.tte.tcommon
 * @ClaseName: t
 * @Description: t
 * @Author: DongWH
 * @Date: 2022/4/18 18:09
 * @params *@params $
 */
import java.awt.Container;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class LoginSystem{
    TextField tf_name;
    TextField tf_pass;

    public LoginSystem() {
        JFrame f=new JFrame();
        f.setTitle("用户登录界面");
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.addWindowListener(new WindowAdapter(){
            //重写关闭窗口方法
            public void windowClosing(WindowEvent e){
                System.exit(0);
            }
        });
        f.setExtendedState(JFrame.MAXIMIZED_BOTH);
        f.setSize(400,400);
        //f.setLocation(200,200);
        f.setLocationRelativeTo(null);

        Container con=f.getContentPane();
        con.setLayout(new GridLayout(5, 1));

        JPanel pan1=new JPanel();
        Icon pic=new ImageIcon("src/图片/学校.jpg");
        JLabel j_pic=new JLabel(pic);
        pan1.add(j_pic);
        con.add(pan1);

        JPanel pan2=new JPanel();
        JLabel title=new JLabel("欢迎登录");
        title.setFont(new Font("宋体",Font.BOLD,20));
        pan2.add(title);
        con.add(pan2);

        JPanel pan3=new JPanel();
        JLabel name=new JLabel("用户名：");
        pan3.add(name);
        tf_name=new TextField(20);
        tf_name.setText("请在此输入用户名");
        pan3.add(tf_name);
        con.add(pan3);

        JPanel pan4=new JPanel();
        JLabel pass=new JLabel("密码    ：");
        pan4.add(pass);
        tf_pass=new TextField(20);
        tf_pass.setText("请在此输入密码");
        pan4.add(tf_pass);
        con.add(pan4);

        JPanel pan5=new JPanel();
        JButton b_log=new JButton("登录");
        b_log.addActionListener(new ActionListener(){
            //重写按钮事件响应方法
            public void actionPerformed(ActionEvent e){
                //调用自定义的"确定"的按钮响应方法
                btnOkActionPerFormed(e);
            }
        });
        pan5.add(b_log);
        JButton b_exit=new JButton("退出");
        b_exit.addActionListener(new ActionListener(){
            //重写按钮事件响应方法
            public void actionPerformed(ActionEvent e){
                //调用系统的退出方法
                System.exit(0);
            }
        });
        pan5.add(b_exit);
        con.add(pan5);
    }
    //自定义的"确定"按钮响应方法
    public void btnOkActionPerFormed(ActionEvent e){
        Frame fm = new Frame();
        String userName = tf_name.getText();
        String userPass = tf_pass.getText();
        if(userName.equals("TTE")&&userPass.equals("123")){
            JOptionPane.showMessageDialog(null, "登录成功");
            fm.dispose();
        }
        else
        {
            JOptionPane.showMessageDialog(null, "登录失败");
            fm.dispose();//关闭窗体后释放窗体资源
        }
    }
    public static void main(String[] args) {
        new LoginSystem();
    }
}